
{extend name='bus@public/wrap'}

{block name="main"}
<style>
    .form-inline .form-control {
        display: inline-block;
        width: 90%;
        vertical-align: middle;
    }
</style>
<main role="main">
    <div class="container-fluid">
        <form class="mt-5" id="form_data">
            <div class="form-inline form-group form-row">
                <div class="form-group col-sm-6 form-row">
                    <label class="col-sm-3">工  号</label>
                    <div class="col-sm-9">
                        <input type="text" class="form-control" name="number" value="{$user.number}" disabled>
                    </div>
                </div>
                <div class="form-group col-sm-6 form-row">
                    <label class="col-sm-3">帐  号</label>
                    <div class="col-sm-9">
                        <input type="text" class="form-control" name="account" value="{$user.account}" disabled>
                    </div>
                </div>
            </div>

            <div class="form-inline form-group form-row">
                <div class="form-group col-sm-6 form-row">
                    <label class="col-sm-3">密  码</label>
                    <div class="col-sm-9">
                        <input type="password" class="form-control" name="password" value="{$user.password}" placeholder="请输入密码" >
                    </div>
                </div>
                <span class="font-weight-light">请填写6到12位密码，修改时密码留空则不改密码</span>
            </div>

            <div class="form-inline form-group form-row">
                <div class="form-group col-sm-6 form-row">
                    <label class="col-sm-3">姓  名</label>
                    <div class="col-sm-9">
                        <input type="text" class="form-control" name="name" value="{$user.name}"  placeholder="请输入用户姓名" >
                    </div>
                </div>
                <div class="form-group col-sm-6 form-row">
                    <label class="col-sm-3">性  别</label>
                    <div class="col-sm-9">
                        <select name="sex" class="form-control" placeholder="请选择性别" >
                            <option value="男" {eq name="$user.sex" value="男"}selected="selected"{/eq}>男</option>
                            <option value="女" {eq name="$user.sex" value="女"}selected="selected"{/eq}>女</option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="form-inline form-group form-row">
                <div class="form-group col-sm-6 form-row">
                    <label class="col-sm-3">电  话</label>
                    <div class="col-sm-9">
                        <input type="text" class="form-control" name="mobile" value="{$user.mobile}" placeholder="请输入电话" >
                    </div>
                </div>
                <div class="form-group col-sm-6 form-row">
                    <label class="col-sm-3">邮  箱</label>
                    <div class="col-sm-9">
                        <input type="text" class="form-control" name="mail" value="{$user.mail}"  placeholder="请输入邮箱" >
                    </div>
                </div>
            </div>

            <div class="mt-5 mb-5 bd-example text-center">
                <input type='hidden' value='{$Think.get.id}' name='id'/>
                <input class="btn btn-secondary mr-2" type="button" value=" 保存数据 " id="submit">
                <input class="btn btn-secondary ml-2" type="button" value=" 取消编辑 " id="close">
            </div>

        </form>
    </div>
</main>

<script>


    //取消编辑
    $("#close").on("click",function () {
        //询问框
        top.layer.confirm('你确定要取消编辑吗？', {
            btn: ['确定','取消']
        }, function(){
            top.layer.closeAll();
            parent.layer.closeAll();
        });
    });

    //提交数据
    $("#submit").on("click",function () {

        if($(this).hasClass("having")){
            return;
        }

        $(this).addClass("having");

        var data = $("#form_data").serializeObject();

        $.ajax({
            url:"/admin/index/edit",
            type:"post",
            data:data,
            success:function(data){
                ptshow(data);
                if(data.code == 0){

                    parent.layer.closeAll();

                }else{
                    $("#submit").removeClass("having");
                }
            },
            error: function (err) {
                console.log(err)
            }
        });
    });

</script>
{/block}